<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax登录页面</title>
    <script src="/static/js/jquery-1.11.3.min.js"></script>
    <script>
        $(function () {
            $('#btnlogin').click(function () {
                //1.获取用户名和密码
                username=$('#username').val()
                password=$('#password').val()
                //2.发起ajax请求 /login_ajax_check, 携带用户名和密码
                $.ajax({
                    'url':'/login_ajax_check',
                    'type':'post',
                    'data':{'username':username, 'password':password},
                    'dataType':'json'//返回格式json
                }).success(function (data) {
                    //登陆成功res:1
                    //登陆失败res:0
                    if (data.res ==0){
                       $('#errmsg').show().html('用户名或密码错误')
                    }
                    else{
                        //跳转到首页
                        location.href='/uumei'
                    }
                })
            })
        })
    </script>
    <style>
        #errmsg{
            display:none;
            color:red;

        }
    </style>
</head>
<body>
<div>
    用户名:<input type='text' id="username"><br/>
    密码:<input type="text" id="password"><br/>
    <input type="button" id="btnlogin" value="登录">
    <div id="errmsg"></div>
</div>
</body>
</html>